Automating Studio Products

Your application provides a new, industry standard interface that allows you to write scripts using any COM-aware scripting language. JavaScript is popular, but any language that can access the COM layer will be fine.

Scripts are typically embedded into an HTML document, which can then be loaded into the Customization window in a Studio product to execute. You can drag-and-drop scripts in an .htm or .html document to load them automatically.

As well as running individual commands from scripts you can also run your existing macros which have long been a feature of Datamine Studio products.

The following figure shows a typical script in the Customization window (in this case, of Studio OP but this control bar is similar in all Datamine products):.

As a web page, of course, you can create your own interface and controls.

Script Browser Permissions

Scripts will commonly make use of a DmApplication object, which hosts the hierarchy of methods, properties and events that you can access to automate Studio functions and your workflows.

Access to the DmApplication object is typically can be accessed through the instantiation of an ActiveX control.

Datamine Studio's embedded Customization window is based on Microsoft browser technology. In order to run customization scripts, the relevant permissions must be set. You can find out more about this via the following knowledge base articles (login required):

Tip: You can avoid the instantiation of ActiveX controls in Studio scripts by setting the reference to the DmApplication object using the window.external object. For example, oDmApp = window.external; (Javascript).

Script Example

Consider the following example, which displays two file browser windows to define an input and output file. The selected file names are stored in the parent screen's tbInput and tbOutput list controls. This example doesn't do anything else, but it could easily be extended to perform a function on the input file (a design command or process), saving the output accordingly.

The popup screen is an HTML table, using HTML text, buttons, text boxes and other controls.  The HTML is written so that when a button is pressed, a short section of JavaScript is executed to carry out some function, such as using the Project File browser, or running some commands.

The HTML code used to represent the above table is as follows:

<TABLE cellSpacing=0 cellPadding=10 align=left border=0>

  <TBODY>

  <TR>

    <TD>

      <TABLE

      style="BORDER-RIGHT: 2px outset; BORDER-TOP: 2px outset; FONT-SIZE: 10pt; BORDER-LEFT: 2px outset; BORDER-BOTTOM: 2px outset; FONT-FAMILY: MS Sans Serif; BACKGROUND-COLOR: buttonface"

      cellSpacing=0 cellPadding=5 align=left border=0>

        <TBODY>

        <TR>

          <TD colSpan=3><B>Example scripted dialog interface</B>

            <HR>

          </TD></TR>

        <TR>

          <TD>Input file</TD>

          <TD><INPUT name=tbInput></TD>

          <TD><INPUT language=javascript style="WIDTH: 30px" onclick="return btnBrowse1_onclick()" type=button value=... name=btnBrowse1></TD></TR>

        <TR>

          <TD>Output file</TD>

          <TD><INPUT name=tbOutput></TD>

          <TD><INPUT language=javascript style="WIDTH: 30px" onclick="return btnBrowse2_onclick()" type=button value=... name=btnBrowse2></TD></TR>

        <TR>

          <TD align=middle colSpan=3><INPUT language=javascript style="WIDTH: 75px" onclick="return btnOK_onclick()" type=button value=OK name=btnOK></TD></TR></TBODY></TABLE>

      <P>&nbsp;</P></TD></TR></TBODY></TABLE>

The JavaScript code used to activate this popup is greatly simplified by using the Datamine basic Script Library Component (SLC). The JavaScript code to initialize the SLC is already included in the auto-saved file, and is similar to the following:

<SCRIPT language=javascript id=clientEventHandlersJS>

<!--

var dm = null;

function window_onload() {

if (typeof(top.DCM) != 'object' || top.DCM == null)

top.DCM = new ActiveXObject('DMComServer.DMCommandManager');

dm=top.DCM;

if (typeof(top.dmBrowser) != 'object' || top.dmBrowser == null)

dmBrowser = new ActiveXObject('DMBrowserCtl.DMBrowserCtl');

top.dmBrowser.connect("name=");

var commonDir = window.dialogArguments;

document.images("logo").src = commonDir + "/images/dmlogo200x93.gif";

var cell = document.all("clear")

}

function window_onunload() {

dm = null;

dmBrowser = null;

}

function btnBrowse1_onclick() {

top.dmBrowser.popup();

tbInput.value = top.dmBrowser.selectedTable;

}

function btnBrowse2_onclick() {

top.dmBrowser.Popup();

tbOutput.value = top.dmBrowser.selectedTable;

}

function btnOK_onclick() {

alert("This button can execute the\ncommands that you have recorded");

}

function btnClose_onclick() {

window.close();

}

//-->

</SCRIPT>

Then, to add JavaScript functionality to use the Project File browser to prompt for the name of the input file, and then a snippet to write that name into the text box can be as easy as:

tbInput.value = dm.browseForFile();

More Information

  • See your Scripting Tutorial, available from the Help menu.

  • Datamine also offers comprehensive training courses that will teach you how to use scripting to get the best out of your system. Contact your Datamine Support Representative for more information.